<?php

namespace App\Http\Controllers;

use App\ActivityOrder;
use Illuminate\Http\Request;

class ActivityOrderController extends Controller
{
    public function index()
    {
        $activityOrder = ActivityOrder::latest('created_at')->Paginate(8);
        return view('Activity.activityOrder',compact('activityOrder'));
    }

    public function destroy($id)
    {
        $activityOrder = ActivityOrder::find($id);
        $activityOrder->delete();

        session()->flash('success', '删除成功');
        return redirect()->route('activityOrder.index');
    }

    public function edit($id){
        $activityOrder=ActivityOrder::findOrFail($id);
        return view('Activity.activityOrderEdit',compact('activityOrder'));
    }

    public function update(Request $request,$id){
        $activityOrder=ActivityOrder::findOrFail($id);
        $activityOrder->update([
            'activity_name'=>$request->get('activity_name'),
            'activity_price'=>$request->get('activity_price'),
            'username'=>$request->get('username'),
            'count'=>$request->get('count'),
            'phone'=>$request->get('phone'),
            'rules'=>$request->get('rules')
        ]);
        $activityOrder->save();
        session()->flash('success',"信息更新");
        return redirect()->route('activityOrder.index');
    }
}
